function [Clusters, LL, Sigma1, mu1, mixmat1, transmat1] = TestFlightDiv(Riabn, Q)
%Let us generate nex=50 vector-valued sequences of length T=50; each vector has size O=2.
O = size(Riabn, 2);
T = size(Riabn, 1);
nex = 1;
data=zeros(O,T,1);
data(:,:,1)=Riabn';

%data = randn(O,T,nex);
%Now let use fit a mixture of M=2 Gaussians for each of the Q=2 states using K-means.
M = 1;
LL = -inf;
left_right = 0;
for i=1:10
    prior0 = rand(1,Q);
    prior0 = prior0/sum(prior0);
    transmat0 = mk_stochastic(rand(Q,Q));
    reshape(data, [O T*nex]);
    %pause
    [mu0, Sigma0] = mixgauss_init(Q*M, reshape(data, [O T*nex]), 'full');
    %pause
    mu0 = reshape(mu0, [O Q M]);
    Sigma0 = reshape(Sigma0, [O O Q M]);
    mixmat0 = mk_stochastic(rand(Q,M));
    %pause

    %Finally, let us improve these parameter estimates using EM.
    [LL1, prior2, transmat2, mu2, Sigma2, mixmat2] = ...
        mhmm_em(data, prior0, transmat0, mu0, Sigma0, mixmat0, 'max_iter', 100);
    if(max(LL1 - 0.5*Q*log(T))>LL)
        LL = max(LL1-0.5*Q*log(T))
        prior1 = prior2;
        transmat1 = transmat2;
        mu1 = mu2;
        Sigma1 = Sigma2;
        mixmat1 = mixmat2;
    end
end

B = mixgauss_prob(data(:,:,1),mu1, Sigma1, mixmat1);
[Clusters] = viterbi_path(prior1, transmat1, B);   